package com.huawei.appmarket.service.distribution.minidetail;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Parcelable;
import android.text.TextUtils;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.widget.RelativeLayout;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol;
import com.huawei.appgallery.foundation.service.common.protocol.AppListFragmentProtocol;
import com.huawei.appgallery.foundation.service.common.protocol.request.AppListFragmentRequest;
import com.huawei.appgallery.foundation.ui.framework.activity.BaseActivity;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse.Layout;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.e;
import com.huawei.appgallery.foundation.ui.framework.uikit.ContractFragment;
import com.huawei.appmarket.R;
import com.huawei.appmarket.framework.coreservice.DataHolder;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailHeadBean;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailHiddenBean;
import com.huawei.appmarket.service.appdetail.view.AppNoContentFragmentProtocol;
import com.huawei.appmarket.service.distribution.authentication.bean.AgdSecurityVerificationRequest;
import com.huawei.appmarket.service.distribution.authentication.bean.AgdSecurityVerificationResponse;
import com.huawei.appmarket.service.distribution.deeplink.fulldetail.DisFullDetailActivityProtocol;
import com.huawei.appmarket.service.distribution.minidetail.MiniDetailFragmentProtocol.Request;
import java.util.List;
import o.azb;
import o.cfv;
import o.cin;
import o.cjk;
import o.cjm;
import o.cjo;
import o.cvt;
import o.dgm;
import o.Logger;
import o.dph;
import o.dpi;
import o.drj;
import o.drr;
import o.dxh;
import o.dxi;
import o.dxl;
import o.dxn;
import o.dxq;
import o.eib;
import o.epv;
import o.epw;
import o.CollectCheck;
import o.FragmentManager;
import o.FragmentTransaction;
import org.json.JSONException;
import org.json.JSONObject;

public class MiniDetailActivity extends BaseActivity<MiniDetailActivityProtocol> implements e {
    private boolean ʻॱ = false;
    private int ˊॱ = -1;
    private AgdSecurityVerificationResponse ˋॱ = new AgdSecurityVerificationResponse();
    private MiniDetailActivityProtocol ˏॱ;
    private String ͺ = null;
    private RelativeLayout ॱˊ;
    private dxn ॱˋ;
    private b ॱˎ;

    static {
        dpi.ˎ(MiniDetailActivity.class);
    }

    public void onCreate(@Nullable Bundle bundle) {
        requestWindowFeature(1);
        super.onCreate(bundle);
        setContentView(R.layout.distribute_mini_detail_activity);
        this.ॱˊ = (RelativeLayout) findViewById(R.id.mini_detail_layout);
        eib.ॱ(this);
        ˊˋ();
        setFinishOnTouchOutside(true);
        this.ˏॱ = (MiniDetailActivityProtocol) ʾ();
        if (bundle != null) {
            this.ʻॱ = bundle.getBoolean("empty_content_fragment", false);
            if (this.ʻॱ) {
                this.ॱˊ.setBackgroundColor(getResources().getColor(R.color.emui_white));
            }
        } else if (ᐝ()) {
            cjo ˏ;
            if (this.ॱˋ != null) {
                ˏ = DefaultMiniDetailFragment.ˏ((Activity) this, this.ॱˋ.ʼ(), this.ˏॱ.ˏ().ॱˎ());
            } else {
                ˏ = DefaultMiniDetailFragment.ˎ(this, this.ˏॱ.ˏ().ˎˎ(), this.ˏॱ.ˏ().ॱˎ());
            }
            Fragment ˊ = cjk.ˎ().ˊ(new cjm("default.mini.detail.fragment", ˏ));
            if (ˊ instanceof TaskFragment) {
                ((TaskFragment) ˊ).ˋ(ˏॱ(), R.id.mini_detail_layout, "TaskFragment");
            }
        } else if (ͺ()) {
            ᐝॱ();
        } else {
            ˋ(null);
        }
    }

    private boolean ᐝ() {
        if (this.ˏॱ == null || this.ˏॱ.ˏ() == null) {
            Logger.ˎ("MiniDetailActivity", "protocol is empty!");
            return false;
        }
        Intent intent = getIntent();
        if (intent == null) {
            return false;
        }
        Object parcelableArrayListExtra = intent.getParcelableArrayListExtra("start_download_request");
        if (!CollectCheck.isEmpty(parcelableArrayListExtra)) {
            Parcelable parcelable = (Parcelable) parcelableArrayListExtra.get(0);
            if (parcelable instanceof DataHolder) {
                DataHolder dataHolder = (DataHolder) parcelable;
                if (dataHolder.ˊ() != null) {
                    this.ॱˋ = new dxn(dataHolder);
                    return true;
                }
            }
        }
        return ॱˊ();
    }

    private boolean ॱˊ() {
        return "1".equals(this.ˏॱ.ˏ().ˊˊ());
    }

    private boolean ͺ() {
        if (this.ˏॱ == null || this.ˏॱ.ˏ() == null) {
            Logger.ˎ("MiniDetailActivity", "protocol is empty!");
            return false;
        }
        Object ˋˊ = this.ˏॱ.ˏ().ˋˊ();
        if (TextUtils.isEmpty(ˋˊ)) {
            Logger.ˎ("MiniDetailActivity", "response json is empty!");
            return false;
        }
        try {
            this.ˋॱ.fromJson(new JSONObject(ˋˊ));
        } catch (JSONException e) {
            Logger.ˎ("MiniDetailActivity", "convert json error: JSONException");
        } catch (IllegalAccessException e2) {
            Logger.ˎ("MiniDetailActivity", "convert json error: IllegalAccessException");
        } catch (InstantiationException e3) {
            Logger.ˎ("MiniDetailActivity", "convert json error: InstantiationException");
        } catch (ClassNotFoundException e4) {
            Logger.ˎ("MiniDetailActivity", "convert json error: ClassNotFoundException");
        }
        if (this.ˋॱ == null) {
            Logger.ˎ("MiniDetailActivity", "response is null!");
            return false;
        }
        this.ˋॱ.setResponseCode(0);
        dxq.ˏ(this.ˋॱ);
        return true;
    }

    private void ᐝॱ() {
        ʼॱ();
        ˋ(ˋˊ());
    }

    private void ʼॱ() {
        Logger.ˎ("MiniDetailActivity", "res.getCss(): " + (this.ˋॱ.ॱˎ() == null ? null : this.ˋॱ.ॱˎ().toString()));
        this.ˊॱ = this.ˋॱ.ˊॱ();
        if (epw.ˏ()) {
            this.ˊॱ = 0;
        }
        if (this.ˋॱ.ॱˎ() != null) {
            this.ͺ = this.ˋॱ.ॱˎ().toString();
        }
    }

    private String ˉ() {
        List ʻॱ = this.ˋॱ.ʻॱ();
        if (CollectCheck.isEmpty(ʻॱ)) {
            return null;
        }
        return ((Layout) ʻॱ.get(0)).ˏ();
    }

    private ContractFragment ˋˊ() {
        drr o_drr = new drr();
        drr.ˊ(o_drr, new cfv(), this.ˋॱ);
        DetailHeadBean ˋ = o_drr.ˋ();
        DetailHiddenBean ᐝ = o_drr.ᐝ();
        ContractFragment contractFragment;
        if (ˋ != null && ᐝ != null && !CollectCheck.isEmpty(o_drr.ʽ())) {
            cjo miniDetailFragmentProtocol = new MiniDetailFragmentProtocol();
            Request request = new Request();
            request.ˏ(this.ˏॱ.ˏ().ˏॱ());
            request.ˊ(ˋ);
            ᐝ.ʻॱ(this.ˏॱ.ˏ().ॱˎ());
            Object ʻॱ = this.ˏॱ.ˏ().ʻॱ();
            if (!TextUtils.isEmpty(ʻॱ) && dph.ˋ().ॱ(ʻॱ, ᐝ.ॱـ())) {
                ᐝ.ᐝ(8);
                ᐝ.ʽ(dxi.ॱ(this.ˏॱ.ˏ().ˉ()));
            }
            request.ॱ(this.ˏॱ.ˏ().ˉ());
            request.ᐝ(this.ˏॱ.ˏ().ॱˎ());
            request.ˋ(ᐝ, dgm.ˎ(this));
            request.ˋ(o_drr.ʽ());
            request.ॱॱ(this.ˏॱ.ˏ().ᐝ());
            request.ʽ(this.ˏॱ.ˏ().ˊˊ());
            if (!(this.ͺ == null || ˉ() == null)) {
                request.ˋ(this.ͺ);
                request.ˊ(ˉ());
            }
            request.ˏ(this.ˊॱ);
            request.ˎ(this.ˏॱ.ˏ().ˊᐝ());
            request.ˊ(this.ˏॱ.ˏ().ˊˋ());
            miniDetailFragmentProtocol.ˏ(request);
            contractFragment = (ContractFragment) cjk.ˎ().ˊ(new cjm("minidetail.fragment", miniDetailFragmentProtocol));
            dxh o_dxh = (dxh) contractFragment.ˊ(dxh.class);
            if (o_dxh == null) {
                return contractFragment;
            }
            o_dxh.ˏ(o_drr);
            return contractFragment;
        } else if (ॱˊ()) {
            AppListFragmentRequest appListFragmentRequest = new AppListFragmentRequest();
            cjo appListFragmentProtocol = new AppListFragmentProtocol();
            appListFragmentRequest.ˏ(this.ˊॱ);
            String ˉ = ˉ();
            if (!(this.ͺ == null || ˉ == null)) {
                appListFragmentRequest.ᐝ(this.ͺ);
                appListFragmentRequest.ʼ(ˉ);
            }
            appListFragmentProtocol.ˏ(appListFragmentRequest);
            contractFragment = (ContractFragment) cjk.ˎ().ˊ(new cjm("appdetailoffshelve.fragment", appListFragmentProtocol));
            cin o_cin = (cin) contractFragment.ˊ(cin.class);
            if (o_cin != null) {
                o_cin.ॱ(this.ॱˎ);
            }
            this.ॱˊ.setBackgroundColor(getResources().getColor(R.color.emui_white));
            return contractFragment;
        } else {
            Logger.ˎ("MiniDetailActivity", "response error: headbean: " + ˋ + ",bottombean: " + ᐝ + ",tabinfo: " + o_drr.ʽ());
            return null;
        }
    }

    private void ˋ(Fragment fragment) {
        if (fragment == null) {
            this.ʻॱ = true;
            AppNoContentFragmentProtocol.Request request = new AppNoContentFragmentProtocol.Request();
            request.ॱ(R.drawable.no_search_result);
            request.ˊ(getString(R.string.detail_no_area_content));
            cjo appNoContentFragmentProtocol = new AppNoContentFragmentProtocol();
            appNoContentFragmentProtocol.ˋ(request);
            fragment = cjk.ˎ().ˊ(new cjm("appnocontent.fragment", appNoContentFragmentProtocol));
            this.ॱˊ.setBackgroundColor(getResources().getColor(R.color.emui_white));
        }
        FragmentManager ˏॱ = ˏॱ();
        FragmentTransaction ˊ = ˏॱ.ˊ();
        Fragment findFragmentByTag = ˏॱ.findFragmentByTag("mini_detail_fragment_tag");
        if (findFragmentByTag != null) {
            ˊ.ˏ(findFragmentByTag);
        } else {
            ˊ.ˏ(R.id.mini_detail_layout, fragment, "mini_detail_fragment_tag");
        }
        ˊ.ˏ();
    }

    private void ˊˋ() {
        Window window = getWindow();
        window.setBackgroundDrawableResource(R.color.transparent);
        LayoutParams attributes = window.getAttributes();
        attributes.gravity = 17;
        if (1 == getResources().getConfiguration().orientation) {
            attributes.width = azb.ॱ(this) - (getResources().getDimensionPixelSize(R.dimen.appgallery_dialog_margin_start) * 2);
            attributes.height = (int) (((float) epv.ॱ(this)) * 0.6f);
        }
        if (2 == getResources().getConfiguration().orientation) {
            attributes.width = (int) (((float) azb.ॱ(this)) * 0.6f);
            attributes.height = epv.ॱ(this) - (getResources().getDimensionPixelSize(R.dimen.orientation_landscape) * 2);
        }
        window.setAttributes(attributes);
    }

    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        ˊˋ();
    }

    public void onMultiWindowModeChanged(boolean z) {
        super.onMultiWindowModeChanged(z);
        ˊˋ();
    }

    public void setTitle(CharSequence charSequence) {
    }

    public boolean ˋ(TaskFragment taskFragment, b bVar) {
        this.ॱˎ = bVar;
        if (bVar.ˋ instanceof AgdSecurityVerificationResponse) {
            this.ˋॱ = (AgdSecurityVerificationResponse) bVar.ˋ;
            if (this.ˋॱ.ˊ() != 0) {
                if (dxq.ˋ(this.ˋॱ)) {
                    dxl.ˋ(this.ˋॱ);
                }
                ᐝॱ();
            } else if (ॱˊ()) {
                ˎ(bVar);
                finish();
            } else {
                cjo appDetailActivityProtocol = new AppDetailActivityProtocol();
                AppDetailActivityProtocol.Request request = new AppDetailActivityProtocol.Request();
                request.ˋ(drj.ॱ(this.ॱˋ.ʼ()));
                request.ˎ(true);
                appDetailActivityProtocol.ˏ(request);
                cjk.ˎ().ˋ(this, new cjm("appdetail.activity", appDetailActivityProtocol));
                finish();
            }
        }
        return true;
    }

    private void ˎ(b bVar) {
        cjo disFullDetailActivityProtocol = new DisFullDetailActivityProtocol();
        DisFullDetailActivityProtocol.Request request = new DisFullDetailActivityProtocol.Request();
        disFullDetailActivityProtocol.ˋ(request);
        String ˎˎ = this.ˏॱ.ˏ().ˎˎ();
        request.ˋ(drj.ˏ(ˎˎ));
        request.ॱˋ(ˎˎ);
        request.ʽॱ(this.ˏॱ.ˏ().ˋᐝ());
        request.ʿ(this.ˏॱ.ˏ().ˊˊ());
        request.ʾ(this.ˏॱ.ˏ().ˋˋ());
        request.ᐝॱ(this.ˏॱ.ˏ().ˍ());
        request.ʽ(this.ˏॱ.ˏ().ᐝ());
        request.ॱˊ(this.ˏॱ.ˏ().ॱˎ());
        if ((bVar.ˋ instanceof AgdSecurityVerificationResponse) && bVar.ˋ.getResponseCode() == 0) {
            AgdSecurityVerificationResponse agdSecurityVerificationResponse = (AgdSecurityVerificationResponse) bVar.ˋ;
            dxq.ˊ(agdSecurityVerificationResponse);
            try {
                request.ʼॱ(agdSecurityVerificationResponse.toJson());
            } catch (IllegalAccessException e) {
                Logger.e("MiniDetailActivity", "response convert to json fail: IllegalAccessException");
            }
        }
        request.ˎ(true);
        cjk.ˎ().ˋ(this, new cjm("distribution.fulldetail.activity", disFullDetailActivityProtocol));
    }

    public void ˎ(TaskFragment taskFragment, List<cvt> list) {
        if (this.ॱˋ != null) {
            AgdSecurityVerificationRequest ˏ = AgdSecurityVerificationRequest.ˏ(this.ॱˋ, this);
            ˏ.ʽ(1);
            list.add(ˏ);
        } else if (ॱˊ()) {
            list.add(AgdSecurityVerificationRequest.ˋ(this.ˏॱ.ˏ()));
        }
    }

    public void onSaveInstanceState(Bundle bundle) {
        if (bundle == null) {
            bundle = new Bundle();
        }
        bundle.putBoolean("empty_content_fragment", this.ʻॱ);
        super.onSaveInstanceState(bundle);
    }

    public void ᐝᐝ() {
    }
}
